package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SystemDept;
import com.ruoyi.system.service.ISystemDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 部门Controller
 * 
 * @author ruoyi
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/erpsystem/dept")
public class SystemDeptController extends BaseController
{
    @Autowired
    private ISystemDeptService systemDeptService;

    /**
     * 查询部门列表
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(SystemDept systemDept)
    {
        List<SystemDept> list = systemDeptService.selectSystemDeptList(systemDept);
        return success(list);
    }

    /**
     * 导出部门列表
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemDept systemDept)
    {
        List<SystemDept> list = systemDeptService.selectSystemDeptList(systemDept);
        ExcelUtil<SystemDept> util = new ExcelUtil<SystemDept>(SystemDept.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(systemDeptService.selectSystemDeptById(id));
    }

    /**
     * 新增部门
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemDept systemDept)
    {
        return toAjax(systemDeptService.insertSystemDept(systemDept));
    }

    /**
     * 修改部门
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemDept systemDept)
    {
        return toAjax(systemDeptService.updateSystemDept(systemDept));
    }

    /**
     * 删除部门
     */
    @PreAuthorize("@ss.hasPermi('erpsystem:dept:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(systemDeptService.deleteSystemDeptByIds(ids));
    }
}
